package com.qys.erp.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.qys.erp.domain.DeliveryLog;
import com.qys.erp.service.IDeliveryLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 出库记录Controller
 * 
 * @author qys
 * @date 2021-08-21
 */
@RestController
@RequestMapping("/erp/log")
public class DeliveryLogController extends BaseController
{
    @Autowired
    private IDeliveryLogService deliveryLogService;

    /**
     * 查询出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('erp:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeliveryLog deliveryLog)
    {
        startPage();
        List<DeliveryLog> list = deliveryLogService.selectDeliveryLogList(deliveryLog);
        return getDataTable(list);
    }

    /**
     * 导出出库记录列表
     */
    @PreAuthorize("@ss.hasPermi('erp:log:export')")
    @Log(title = "出库记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(DeliveryLog deliveryLog)
    {
        List<DeliveryLog> list = deliveryLogService.selectDeliveryLogList(deliveryLog);
        ExcelUtil<DeliveryLog> util = new ExcelUtil<DeliveryLog>(DeliveryLog.class);
        return util.exportExcel(list, "出库记录数据");
    }

    /**
     * 获取出库记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:log:query')")
    @GetMapping(value = "/{logId}")
    public AjaxResult getInfo(@PathVariable("logId") Long logId)
    {
        return AjaxResult.success(deliveryLogService.selectDeliveryLogById(logId));
    }

    /**
     * 新增出库记录
     */
    @PreAuthorize("@ss.hasPermi('erp:log:add')")
    @Log(title = "出库记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeliveryLog deliveryLog)
    {
        return toAjax(deliveryLogService.insertDeliveryLog(deliveryLog));
    }

    /**
     * 修改出库记录
     */
    @PreAuthorize("@ss.hasPermi('erp:log:edit')")
    @Log(title = "出库记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeliveryLog deliveryLog)
    {
        return toAjax(deliveryLogService.updateDeliveryLog(deliveryLog));
    }

    /**
     * 删除出库记录
     */
    @PreAuthorize("@ss.hasPermi('erp:log:remove')")
    @Log(title = "出库记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{logIds}")
    public AjaxResult remove(@PathVariable Long[] logIds)
    {
        return toAjax(deliveryLogService.deleteDeliveryLogByIds(logIds));
    }
}
